package parsing;

import java.util.LinkedList;

import core.City;

public class ParserCity {

	// Persons Map
	public static LinkedList<City> cities;
//	public static Map<String,LinkedList<City>>  cities;
	// values extracted
	public static int numOfCities;
	public static int cityId;
	
	
	/*
	 * returns the City object with the cityName if exists,
	 * else, returns null
	 * but what if there are multiple cities with the same name???
	 * maybe need to be flag that says if there is a city with the same name in the db
	 */
	public static City getCity(String cityName){
		//remove white spaces and _ from the string
		String altName = cityName.replaceAll("_", " ");
		altName = altName.replaceAll("\\s+", "");
		
		for (City city: cities){
			if ((city.cityName.equals(altName)) || (city.cityName.equals(cityName))){
				//found a match
				return city;
			}
		}
		return null;
	}


	/*
	 * gets the path to the CSV file create continents objects and adds them to
	 * the list
	 */
/*	public static void parserCity(String inputFile) {
		cities = new LinkedList<City>();
		numOfCities = 0;
		cityId = 0;
		String countryId;
		float longtitude;
		float latitude;
		String cityName;

		/* open CSV file */
/*		BufferedReader br = null;
		try {
			br = new BufferedReader(new FileReader(new File(inputFile)));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		try {
			br.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		String currLine = null;
		try {
			currLine = br.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		while (currLine != null) {

			String[] lineParts;
			lineParts = currLine.split(",");

			// String cityId; missing
			longtitude = Float.parseFloat(lineParts[6]);
			latitude = Float.parseFloat(lineParts[5]);
			cityName = lineParts[1];
			countryId = lineParts[0];
			cityName.replaceAll("^\"|\"$", "");
			City city = new City(cityName, longtitude, latitude, countryId,
					cityId);
			cities.add(city);
			numOfCities++;
			cityId++;
			try {
				currLine = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		try {
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
	*/

}
